<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>4-局部组件注册方式</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style></style>
  </head>
  <body>
    <div id="app">
      <!-- 3：挂载组件，并渲染  -->
      <hello-word></hello-word>
      <hello-word></hello-word>
    </div>
    <script>
      // 1：创建局部组件
      var HelloWord = {
        data: function () {
          return {
            info: 'hello',
          };
        },
        template: `<button @click="handle">点击显示：{{info}}</button>`,
        methods: {
          handle: function () {
            this.info = 'hao ya';
          },
        },
      };
      var vm = new Vue({
        el: '#app',
        data: {},
        methods: {},
        // 2: 在vm实例上声明并配置
        components: {
          'hello-word': HelloWord,
        },
      });
    </script>
  </body>
</html>
